<?php
/***************************************************************************
 *                                actions.php
 *                            -------------------
 *   begin                : Friday, July 27, 2012
 *   copyright            : (C) 2011 The Wordpress
 *   email                : linux_of_king@yahoo.com
 ***************************************************************************/
//Begin Table Gia 
header("Cache-Control: no-cache");
header("Pragma: nocache");

$wp_include = "../wp-load.php";
$i = 0;
while (!file_exists($wp_include) && $i++ < 10) {
	$wp_include = "../$wp_include";
}
require($wp_include);

$url	= $_POST['url'];
$tmp	= explode(',', $url);
$mode	= $tmp[0];	

//
// Start of program proper
//
if ( isset($mode) )
{
	global $wpdb, $table_prefix;
	switch( $mode )
	{
		case 'pagination_Order':
			$taxonomy = 'cruise_category';
			$catID = $_POST['catID'];
			$start = $_POST['start'];
			$limit = 3;
			$mysql = $wpdb->get_col("SELECT count(*) AS total 
				FROM $wpdb->posts p 
				INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
				INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
				WHERE tt.term_id=". $catID ." AND tt.taxonomy='{$taxonomy}' AND 
					post_type='cruise' AND post_status='publish' AND post_parent=0;");
			$total = $mysql[0];
			$mysql = $wpdb->get_results("SELECT p.ID, post_title, post_name
				FROM $wpdb->posts p 
				INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
				INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
				WHERE tt.term_id=". $catID ." AND tt.taxonomy='{$taxonomy}' AND 
					post_type='cruise' AND post_status='publish' AND post_parent=0 ORDER BY post_date DESC LIMIT {$start}, {$limit};");
			?>
            <div class="top_cruise">
                <div class="pagercontrol">
                    <?php 
                    if( $total > 0 )
                        echo generate_pagination_ajax('paginationOrder', $catID, $total, $limit, $start). '&nbsp;';
					$terms = get_term_by('id', $catID, $taxonomy);
					?>
                    <a href="<?php echo get_term_link( $terms->slug, $taxonomy ); ?>">View all</a>
                </div>
            </div><!-- top cruise-->
            <?php
            $i = 1;
            foreach( $mysql as $cruises ) {
                $thuoctinh_arr = get_post_meta( $cruises->ID, '_mb_attribute', true );
                ?>
                <article class="cruise"<?php echo (($i == 3) ? '' : ' style="margin-right:10px;"'); ?>>
                    <figure class="featured-thumbnail">
                         <a href="<?php echo get_permalink($cruises->ID); ?>"><?php echo get_the_post_thumbnail($cruises->ID, 'thumbnail'); ?></a>                                   
                    </figure>
                    <h3><a href="<?php echo get_permalink($cruises->ID); ?>"><?php echo $cruises->post_title; ?></a></h3>
                    <p><?php echo GetWords($thuoctinh_arr["tomtat"], 200); ?></p>                        
                </article>
                <?php
                if( $i == 3 )
                    $i = 1;
                $i ++ ;
            }
            break;
		
		case 'reload_Package':
			$tab_info = get_post_meta( intval($_POST['postID']), '_mb_tab_info', true );
			$totalTab = count($tab_info);
			$optPackage = '';
			if( $totalTab > 1 ) {
				for( $i = 0; $i < $totalTab; $i = $i + 2 ) {
					$optPackage .= '<option value="'. $i .'">'. $tab_info[$i]['title'] .'</option>';
				} 
			} else {
				$optPackage .= '<option value=0>Only one cruise package</option>';
			}
			echo json_encode(array( 'optPackage' => $optPackage, 'formURL' => get_permalink($_POST['postID']) ));
			break;
	}
}
exit(0);
?>
